package com.mnxc.gxa.controller;


import com.mnxc.gxa.dto.*;
import com.mnxc.gxa.entity.Menu;
import com.mnxc.gxa.entity.User;
import com.mnxc.gxa.service.IMenuService;
import com.mnxc.gxa.service.impl.UserServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author mnxc
 * @since 2023-06-29
 */
@RestController
@RequestMapping("/menu")
@Api(tags = "菜单相关接口")
public class MenuController {
    @Resource
    IMenuService menuService;

    @GetMapping("/getAll")
    @ApiOperation(value="获取菜单接口",notes="获取所有菜单",httpMethod = "GET",produces = "application/json;charset=utf-8")
    @ApiResponses({
            @ApiResponse(code=1,message = "请求成功"),
            @ApiResponse(code=404,message = "找不到页面"),
            @ApiResponse(code=0,message = "后台服务错误"),
    })
    public Result getAll(){
        return menuService.getAll();
    }

    /*
     * @Author @xiaoshu
     * @Description //获取父级菜单
     * @Date 16:06 2023/7/3
     * @param null
     * @return
     **/
    @GetMapping("/tree")
    @ApiOperation(value="获取树型菜单接口",notes="获取树型菜单",httpMethod = "GET",produces = "application/json;charset=utf-8")
    @ApiResponses({
            @ApiResponse(code=1,message = "请求成功"),
            @ApiResponse(code=404,message = "找不到页面"),
            @ApiResponse(code=0,message = "后台服务错误"),
    })
    public Result getMenusTree(){
        return menuService.getMenusTree();
    }

    /*
     * @Author @xiaoshu
     * @Description //分页查询
     * @Date 10:09 2023/7/1
     * @param:page
     * @param:pageSize
     * @param:condition
     * @return com.mnxc.gxa.dto.Result
     **/
    @GetMapping("/getByPageAndCondition")
    @ApiOperation(value="页面信息分页",notes="将信息分页",httpMethod = "GET",produces = "application/json;charset=utf-8")
    @ApiResponses({
            @ApiResponse(code=1,message = "请求成功"),
            @ApiResponse(code=404,message = "找不到页面"),
            @ApiResponse(code=0,message = "后台服务错误"),
    })
    public Result getByPageAndCondition(int page, int pageSize,QueryMenuDTO query){
        return menuService.getByPageAndCondition(page,pageSize,query);
    }
    /*
     * @Author @xiaoshu
     * @Description //新增用户
     * @Date 11:11 2023/7/1
     * @param menu
     * @return
     **/
    @PostMapping
    @ApiOperation(value="新增菜单接口",notes="新增菜单",httpMethod = "POST",produces = "application/json;charset=utf-8")
    @ApiResponses({
            @ApiResponse(code=1,message = "请求成功"),
            @ApiResponse(code=404,message = "找不到页面"),
            @ApiResponse(code=0,message = "后台服务错误"),
    })
    public Result saveMenu(@RequestBody Menu menu){
        return menuService.saveMenu(menu);
    }
    /*
     * @Author @xiaoshu
     * @Description //启用菜单
     * @Date 11:26 2023/7/1
     * @param menu
     * @return
     **/
    @PutMapping("/active")
    @ApiOperation(value="激活菜单接口",notes="激活菜单",httpMethod = "PUT",produces = "application/json;charset=utf-8")
    @ApiResponses({
            @ApiResponse(code=1,message = "请求成功"),
            @ApiResponse(code=404,message = "找不到页面"),
            @ApiResponse(code=0,message = "后台服务错误"),
    })
    public Result activeUser(@RequestBody Menu menu){
        return menuService.activeMenu(menu);
    }
    /*
     * @Author @xiaoshu
     * @Description //冻结菜单
     * @Date 11:40 2023/7/1
     * @param menu
     * @return
     **/
    @PutMapping("/freeze")
    @ApiOperation(value="冻结菜单接口",notes="冻结菜单",httpMethod = "PUT",produces = "application/json;charset=utf-8")
    @ApiResponses({
            @ApiResponse(code=1,message = "请求成功"),
            @ApiResponse(code=404,message = "找不到页面"),
            @ApiResponse(code=0,message = "后台服务错误"),
    })
    public Result freezeMenu(@RequestBody Menu menu){
        return menuService.freezeMenu(menu);
    }
    /*
     * @Author @xiaoshu
     * @Description //删除菜单
     * @Date 11:47 2023/7/1
     * @param null
     * @return
     **/
    @DeleteMapping
    @ApiOperation(value="删除菜单接口",notes="删除菜单",httpMethod = "DELETE",produces = "application/json;charset=utf-8")
    @ApiResponses({
            @ApiResponse(code=1,message = "请求成功"),
            @ApiResponse(code=404,message = "找不到页面"),
            @ApiResponse(code=0,message = "后台服务错误"),
    })
    public Result deleteMenu(Menu menu){
        return menuService.deleteMenu(menu);
    }
    @PutMapping("/updateMenu")
    @ApiOperation(value="修改菜单接口",notes="修改菜单",httpMethod = "PUT",produces = "application/json;charset=utf-8")
    @ApiResponses({
            @ApiResponse(code=1,message = "请求成功"),
            @ApiResponse(code=404,message = "找不到页面"),
            @ApiResponse(code=0,message = "后台服务错误"),
    })
    public Result updateMenu(@RequestBody Menu menu){
        return menuService.updateMenu(menu);
    }
}

